﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="OrgSingleList.ascx.cs"
    Inherits="com.cngrain.SAFC.Web.res.inc.OrgSingleList" %>
<%@ Register Assembly="NineRays.WebControls.FlyTreeView" Namespace="NineRays.WebControls"
    TagPrefix="NineRays" %>
<style type="text/css">
    #pubDiv table
    {
        border: 0px solid #b5ceed !important;
        line-height: 14px !important;
        height: auto !important;
    }
    #pubDiv tr
    {
        border: 0px solid #b5ceed !important;
        line-height: 14px !important;
        height: auto !important;
    }
    #pubDiv td
    {
        border: 0px solid #b5ceed !important;
        line-height: 14px !important;
        height: auto !important;
    }
    #pubDiv th
    {
        border: 0px solid #b5ceed !important;
        line-height: 14px !important;
        height: auto !important;
    }
</style>

<script type="text/javascript">
    var treeviewID = '<%=dropDownTreeView.ClientID%>';
    function toggleTreeView(ev, hide) {
        var ddTreeView = document.getElementById("ddTreeView");
        ddTreeView.style.display =
                    (hide == null && ddTreeView.style.display == "none") || hide == false ? "" : "none";

        // this is a global function of FlyTreeView runtime
        var rect = ninerays_getElementRect(document.getElementById("<%=txtOrgName.ClientID%>"));

        ddTreeView.style.top = (rect.bottom - 1) + "px";
        ddTreeView.style.left = rect.left + "px";

        ev = ev ? ev : window.event;
        if (ev) ev.cancelBubble = true;
    }
    function getInputText1(selectedValue) {
        selectedValue = selectedValue;
        if (selectedValue.getParent() != null) {
            return getInputText1(selectedValue.getParent()) + '-' + selectedValue.getText();
        }
        else {
            return selectedValue.getText();
        }

    }
    function setInputText() {
        var treeview = CFlyTreeView.getInstanceById(treeviewID);
        var selectedNode = treeview.getSelectedNode();
        var value = selectedNode ? selectedNode.getValue() : "";
        var text = selectedNode ? selectedNode.getText() : "";
        var tvInput = document.getElementById("<%=txtOrgName.ClientID%>");
        var tvInputValue = document.getElementById("<%=hfOrgCode.ClientID%>");
        tvInputValue.value = value;
        tvInput.value = text;

    }
    function treeview_OnSelectedNodeChanged(treeview, oldNode, newNode) {
        if (newNode.getValue().length == 3) {
            newNode.expand();
        }
        else {
            setInputText();
            toggleTreeView();
        }
    }
    function treeview_OnInitialized(treeview) {
        document.onmousedown = document_onmousedown
    }
    function document_onmousedown(ev) {
        // hide treeview when mousedown event 
        // comes from any element except treeview child elements
        var eventSrc = ev && ev.target ? ev.target : event.srcElement;
        var treeviewElement = document.getElementById(treeviewID);
        while (eventSrc) {
            if (eventSrc == treeviewElement) return;
            eventSrc = eventSrc.parentNode;
        }

        toggleTreeView(ev, true);
    }
       
</script>

<div id="pubDiv">
    <asp:HiddenField ID="hfOrgCode" runat="server" />
    <table cellpadding="0" style="border-collapse: collapse">
        <tr valign="middle">
            <td style="width: 240px">
                <input type="text" id="txtOrgName" runat="server" style="width: 100%" />
            </td>
            <td valign="middle" onmousedown="toggleTreeView(event); event.cancelBubble = true;">
                <img src="<%=com.cngrain.SAFC.Common.CommonSet.BaseUrl()+"/res/images/Common/dropdown.gif"%>"
                    alt="" style="width: 16px; height: 21px; border-style: none; vertical-align: middle"
                    onmouseover="this.src = '<%=com.cngrain.SAFC.Common.CommonSet.BaseUrl()+"/res/images/Common/dropdown_over.gif"%>'"
                    onmouseout="this.src = '<%=com.cngrain.SAFC.Common.CommonSet.BaseUrl()+"/res/images/Common/dropdown.gif"%>'" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtOrgName"
                    ErrorMessage="直属库名称不能为空！" Display="Dynamic">*</asp:RequiredFieldValidator>
            </td>
        </tr>
    </table>
    <div style="display: none; position: absolute; width: 256px; z-index: 9999;" id="ddTreeView">
        <NineRays:FlyTreeView ID="dropDownTreeView" runat="server" BackColor="White" ImageSet="Vista"
            Height="300px" Width="100%" BorderColor="Silver" BorderWidth="1px" SlideEffect="True"
            OnSelectedNodeChangedJavascript="treeview_OnSelectedNodeChanged" OnPopulateNodes="dropDownTreeView_PopulateNodes"
            DrawLines="true" Padding="1px" OnInitializedJavascript="treeview_OnInitialized"
            ContentClickExpands="False" PathSeparator="\" DragDropMode="CtrlDefinedMoveDefault"
            ScrollLeft="0" ScrollTop="0" LoadingMessage="加载中 ...">
            <DefaultStyle Font-Names="Tahoma" Font-Size="11px" ForeColor="Black" ImageUrl="$blank"
                RowHeight="18px" Padding="3px;7px;7px;3px" />
            <SelectedStyle BackColor="#D6F0FD" BorderColor="#9ADFFE" BorderStyle="Solid" BorderWidth="1px"
                Padding="2px;6px;6px;2px" />
            <HoverStyle Font-Underline="True" />
        </NineRays:FlyTreeView>
    </div>
</div>
